﻿Date.prototype.add = function(year, month, day, hours, minutes, seconds) {
    var tarDate = new Date();
    tarDate.setYear(this.getYear() + year);
    tarDate.setMonth(this.getMonth() + month);
    tarDate.setDate(this.getDate() + day);
    tarDate.setHours(this.getHours() + hours);
    tarDate.setMinutes(this.getMinutes() + minutes);
    tarDate.setSeconds(this.getSeconds() + seconds);
    return tarDate;
}
Date.prototype.compare = function(date) {
    if (this.getYear() > date.getYear()) {
        return 1;
    }
    else if (this.getYear() < date.getYear()) {
        return -1;
    }
    else if (this.getMonth() > date.getMonth()) {
        return 1;
    }
    else if (this.getMonth() < date.getMonth()) {
        return -1;
    }
    else if (this.getDate() > date.getDate()) {
        return 1;
    }
    else if (this.getDate() < date.getDate()) {
        return -1;
    }
    else if (this.getHours() > date.getHours()) {
        return 1;
    }
    else if (this.getHours() < date.getHours()) {
        return -1;
    }
    else if (this.getMinutes() > date.getMinutes()) {
        return 1;
    }
    else if (this.getMinutes() < date.getMinutes()) {
        return -1;
    }
    else if (this.getSeconds() > date.getSeconds()) {
        return 1;
    }
    else if (this.getSeconds() < date.getSeconds()) {
        return -1;
    }
    else {
        return 0;
    }
}
Date.prototype.toFormatString = function() {
    var year = this.getYear() + 1900;
    var month = (this.getMonth() + 1).toString();
    if (month.length == 1) {
        month = "0" + month;
    }
    var day = this.getDate().toString();
    if (day.length == 1) {
        day = "0" + day;
    }
    var hours = this.getHours().toString();
    if (hours.length == 1) {
        hours = "0" + hours;
    }
    var minutes = this.getMinutes().toString();
    if (minutes.length == 1) {
        minutes = "0" + minutes;
    }
    var seconds = this.getSeconds().toString();
    if (seconds.length == 1) {
        seconds = "0" + seconds;
    }
    return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
}
function parseJsonStringfunction(dateString)
{
    dateString = dateString.replace("/Date(", "").replace(")/", "");
    if (dateString.indexOf("+") > 0) {
        dateString = dateString.substring(0, dateString.indexOf("+"));
    } else if (dateString.indexOf("-") > 0) {
        dateString = dateString.substring(0, dateString.indexOf("-"));
    }
    return new Date(parseInt(dateString, 10)-28800000);
}
Date.prototype.toJsonString=function()
{
    return "/Date("+this.getMilliseconds()+")/";
}